#include<cstdio>
#include<cstring>
#include<cstdlib>

const int maxn = 1010;
int T;
int M;
int N;

int father[maxn];

void init(){
	for(int i = 1; i <= N; i ++){
		father[i] = i;
	}
}

int getFather(int a){
	if(father[a] == a){
		return a;
	}else{
		father[a] = getFather(father[a]);
		return father[a];
	}
}

void unionSets(int a, int b){
	father[a] = getFather(father[a]);	
	father[b] = getFather(father[b]);
	if(father[a] != father[b]){
		int faA = father[a];
		father[faA] = father[b]; 
	}
}

int getSetsNum(){
	int count = 0;
	for(int i = 1; i <= N; i ++){
		if(father[i] == i){
			count ++;
		}
	}
	return count;
}

int main(void){
	scanf("%d", &T);
	for(int i = 0; i < T; i ++){
		scanf("%d%d", &N, &M);
		init();//
		for(int ii = 0; ii < M; ii ++){
			int A, B;
			scanf("%d%d", &A, &B);
			unionSets(A, B);//
		}
		printf("%d\n", getSetsNum());//		
	}
	return 0;
}
